#include "Heater.h"

void Heater::Stop(void)
{
  halOutput->toggle_heater(false);
}

void Heater::Heat(int temp)
{
  halOutput->toggle_heater(true);
  int value = 0;
  //Serial.print("0:");
  //Serial.println(value);
  halInput->update();
  value = halInput->readTemperature();
  while((value*33) < temp)
  {
    halInput->update();
    value = halInput->readTemperature();
  }

  halOutput->toggle_heater(false);
}

void Heater::KeepHeat(int temp, int duration)
{
  long starttime = millis();
  halInput->update();
  int value = halInput->readTemperature();
  while(millis() - starttime < duration){
    halInput->update();
    value = halInput->readTemperature();
    if((value*33) < temp){
      halOutput->toggle_heater(true);
    }else{
      halOutput->toggle_heater(false);
    }
  }
  halOutput->toggle_heater(false);
}

